﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UsersReg;

namespace Sales_and_Services_Monitoring_System
{
    public partial class mainfrm : Form
    {
        dBase db = new dBase();
        public DataTable tbl = new DataTable();


        public mainfrm()
        {
            InitializeComponent();
            OpenData.Click += new EventHandler(OpenData_Click);
            Exit.Click += new EventHandler(Exit_Click);
            /*AddProduct.Click += new EventHandler(AddProduct_Click);
            ViewProduct.Click += new EventHandler(ViewProduct_Click);
            this.Load += new EventHandler(Form2_Load);
            txtSearch.TextChanged += new EventHandler(txtSearch_TextChanged);
            btnSearch.Click += new EventHandler(btnSearch_Click);
            ViewUser.Click += new EventHandler(ViewUser_Click);
            About.Click += new EventHandler(About_Click);
            RegisterUsers.Click += new EventHandler(RegisterUsers_Click);
            MenuUpdateQty.Click += new EventHandler(MenuUpdateQty_Click);
            MenuViewCostumer.Click += new EventHandler(MenuViewCostumer_Click);
            MenuViewSupplier.Click += new EventHandler(MenuViewSupplier_Click);
            MenuAddCostumer.Click += new EventHandler(MenuAddCostumer_Click);
            MenuAddSupplier.Click += new EventHandler(MenuAddSupplier_Click);*/
            
        }

        void Exit_Click(object sender, EventArgs e)
        {
            Application.Restart();
            this.Close();
        }

       /* void MenuAddSupplier_Click(object sender, EventArgs e)
        {
            NewSupplier frm = new NewSupplier();
            frm.ShowDialog();
        }

        void MenuAddCostumer_Click(object sender, EventArgs e)
        {
            NewCostumer frm = new NewCostumer();
            frm.ShowDialog();
        }

        void MenuViewSupplier_Click(object sender, EventArgs e)
        {
            Supplier frm = new Supplier();
            frm.ShowDialog();
        }


        void MenuViewCostumer_Click(object sender, EventArgs e)
        {
            Costumer frm = new Costumer();
            frm.ShowDialog();

        }

        void MenuUpdateQty_Click(object sender, EventArgs e)
        {
            Update frm = new Update();
            frm.ShowDialog();
        }

        void ViewUser_Click(object sender, EventArgs e)
        {

            Accounts frmAccounts = new Accounts();
            frmAccounts.ShowDialog();

        }

        void RegisterUsers_Click(object sender, EventArgs e)
        {
            SignUp frmSignUp = new SignUp();
            frmSignUp.ShowDialog();
        }

        void About_Click(object sender, EventArgs e)
        {
            About frm = new About();
            frm.ShowDialog();
        }

        

        void btnSearch_Click(object sender, EventArgs e)
        {
            SearchProduct();
        }

        void txtSearch_TextChanged(object sender, EventArgs e)
        {
            SearchProduct();
        }*/



      /*  public void AccessData(string position)
        {
            switch (position)
            {
                case "Admin":
                    AddProduct.Enabled = true;
                    OpenData.Enabled = true;
                    ViewProduct.Enabled = true;
                    ManageAccounts.Enabled = true;
                    MenuAddITEM.Enabled = true;
                    MenuViewCostumer.Enabled = true;
                    MenuViewSupplier.Enabled = true;
                    MenuUpdateQty.Enabled = true;
                    break;
                case "Cashier":
                    AddProduct.Enabled = false;
                    ViewProduct.Enabled = true;
                    ManageAccounts.Enabled = false;
                    grid.Enabled = false;
                    MenuAddITEM.Enabled = false;
                    MenuUpdateQty.Enabled = false;
                    MenuViewCostumer.Enabled = true;
                    MenuViewSupplier.Enabled = true;
                    break;
                case "Inventory Officer":
                    AddProduct.Enabled = false;
                    ViewProduct.Enabled = true;
                    ManageAccounts.Enabled = false;
                    grid.Enabled = false;
                    MenuAddITEM.Enabled = false;
                    MenuUpdateQty.Enabled = false;
                    MenuViewCostumer.Enabled = true;
                    MenuViewSupplier.Enabled = true;
                    break;
            }
        }*/


        void SearchProduct()
        {
            if (txtSearch.Text != "")
            {
                db.connect();
                string sql = "SELECT * FROM tblProducts WHERE fProductName LIKE '%" + txtSearch.Text + "%'";
                db.query(sql);
                tbl = db.dtl;
                grid.DataSource = tbl;
                db.close();
            }
        }



        void view()
        {
            db.connect();
            db.productView();
            tbl = db.dtl;
            grid.DataSource = tbl;
            db.close();
        }


        /*void Form2_Load(object sender, EventArgs e)
        {
            db.connect();
            db.close();
            timer1.Start();


        }


        void ViewProduct_Click(object sender, EventArgs e)
        {
            Product frm = new Product();
            frm.ShowDialog();
        }

        void AddProduct_Click(object sender, EventArgs e)
        {
            NewProduct frm = new NewProduct();
            frm.ShowDialog();
        }*/

        void OpenData_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(@".\\Registration.accdb");
        }






    }
}
